extends MoveStateResource


class_name DistanceStateResource


enum DistanceMode
{
    X,
    Y,
    Distance,
}


@export var mode: DistanceMode = DistanceMode.Distance
@export var distance: float = 0


func enter(ctrl: MoveController, data: Dictionary) -> void:
    data.start_position = ctrl.move_component.wrapper.position
    data.squared_distance = distance * distance

func is_distance(ctrl: MoveController, data: Dictionary) -> float:
    var pos: Vector2 = ctrl.move_component.wrapper.position
    match mode:
        DistanceMode.X:
            return abs(pos.x - data.start_position.x) >= distance
        DistanceMode.Y:
            return abs(pos.y - data.start_position.y) >= distance
        DistanceMode.Distance:
            return pos.distance_squared_to(data.start_position) >= data.squared_distance
    return 0

func update(ctrl: MoveController, data: Dictionary, delta: float, duration: float) -> bool:
    if is_distance(ctrl, data):
        return true
    return false
